/**
 * 微信分享
 */

var wxShare = function () {
    var url = location.href.split("#")[0];
    //分享给好友
    var _getVideoFriendUi = function () {
        return ('<img src="' + staticData.shareBg + '" style="display: block;position: absolute;width: 100%;left:0px;top: -175px";>' +
            '<div id="wx_share_popup" style="text-align: center; font-size:16px">' +
            '<div id="wx_share_content" ><div style="margin-bottom: 10px">由于<span style="color:red;font-size: 20px;">版权原因</span></div>请点击右上角，分享到<span style="color:red;font-size: 20px;">微信群</span></div>' +
            '<div style="margin-top: 10px">即可<span style="color:red;font-size: 20px;">免流量</span>观看</div>' +
            '</div>');
    };
    //分享给好友
    var _getShareFriendUi = function () {
        return ('<img src="' + staticData.shareBg + '" style="display: block;position: absolute;width: 100%;left:0px;top: -175px";>' +
            '<div id="wx_share_popup" style="text-align: center; font-size:16px">' +
            '<div id="wx_share_content" ><div style="margin-bottom: 10px">接下来会更精彩</div>请点击右上角，分享到<span style="color:red;font-size: 20px;">微信群</span></div>' +
            '<div style="margin-top: 10px">即可<span style="color:red;font-size: 20px;">免流量</span>观看</div>' +
            '</div>');
    };
    /**
     * 分享完成的ui
     * @param num
     * @returns {string}
     * @private
     */
    var _shareOkUi = function (num) {
        return '<div style="text-align:center">再分享<span style="color:red;font-size: 20px;"><span style="color:red;font-size: 20px;"> ' + num + ' </span>个微信群</span></div>';
    };

    /**
     * 分享完成的ui
     * @param num
     * @returns {string}
     * @private
     */
    var _shareErrorUi = function () {
        return '<div style="text-align:center">分享<span style="color: red">失败</span>：请分享到<span style="color:red;font-size: 20px;"><span style="color:red;font-size: 20px;"> 不同的微信群</span></span></div>';
    };

    /**
     * 分享完成的ui
     * @param num
     * @returns {string}
     * @private
     */
    var _shareFriendUi = function () {
        return '<div style="text-align:center">最后一步，请分享到<span style="color:red;font-size: 20px;"><span style="color:red;font-size: 20px;"> 朋友圈吧！ </span></span></div>';
    };
    //视频弹框
    this.openTxVideoPopup = function (url) {
        var html = _getShareFriendUi();
        layer.open({
            content: html,
            shadeClose: false
        });
    };
    /**
     * 设置分享次数
     * @param num 2,4
     * @private
     */
    this.addShareNum = function (num) {
        var html;
        switch (parseInt(staticData.shareNum)) {
            case 1: {
                num++;
                html = "分享完成";
                staticData.localStorage.set(staticData.shareLimitKey, num, 60 * 60);
                $("#wx_share_content").html(html);

                break;
            }
            case 2: {
                if (staticData.shareNum - num == 1) {
                    html = _shareFriendUi();
                    num++;
                }
                staticData.localStorage.set(staticData.shareLimitKey, num, 60 * 60);
                $("#wx_share_content").html(html);
                break;
            }
            case 4: {
                if (num == 2) {
                    html = _shareErrorUi();
                } else if (staticData.shareNum - num == 0) {
                    html = _shareFriendUi();
                } else {
                    var uiNum = staticData.shareNum - num;
                    if (num === 1) {
                        uiNum--;
                    }
                    html = _shareOkUi(uiNum);
                }
                staticData.localStorage.set(staticData.shareLimitKey, num, 60 * 60);
                $("#wx_share_content").html(html);
                break;
            }
        }
    };
};